#!/bin/bash

#print
usage(){
	local name=${0##*/}
	cat >&2 <<EOF
usage: $name <action> daemons option

option: 
	start 
	restart 
	stop

EOF
}

(( $# < 1 )) && usage

if [[ $# -ge 2 ]];then
	mod=$1
	action=$2
elif [[ $# -eq 1 ]];then
	mod=$1
	read -p "输入对"$1"的操作[start|restart|stop]:" action
elif [[ $# -eq 0 ]];then
	read -p "输入操作对象:" mod
	read -p " 输入操作[start|restart|stop]" action
fi

if [[ `ls /etc/rc.d/|grep "^$mod"` ]]; then
	echo "开始对$mod操作!"
else
	echo "没有$mod,Quit!"
	exit
fi

if [[ "$action" -eq "start" || "$action" -eq "restart" || "$action" -eq "stop" ]]; then
	echo  "开始对$mod进行$action操作!"
	echo "/etc/rc.d/"$mod $action
	sudo "/etc/rc.d/"$mod $action
else
	echo "没有$action操作!Quit!"
	exit
fi

